//RGB灯

const int RPin = 9;
const int GPin = 10;
const int BPin = 11;
String arrStr[4];

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.available(RPin, judge(arrStr[0]));
  Serial.available(GPin, judge(arrStr[1]));
  Serial.available(BPin, judge(arrStr[2]));
  delay(1000);
}

int judge(String str) {
  if (str.toInt() > 255) {
    return 255;
  }
  return str.toInt();
}



void serialEvent() {
  int i = 0;
  char arr[15];
  while (Serial.available()) {
    arr[i] = Serial.read();
    i++;
  }
  String str = arr;
  String str01 = "";
  int RGBJudge = 0;

  int index = 0;
  for (int i = 0; i < sizeof(arr) / sizeof(char); i++) {
    if (arr[i] == '-' || i == sizeof(arr) / sizeof(char) - 1) {
      arrStr[index] = str01;
      index++;
      str01 = "";
    } else
      str01 += arr[i];
  }
}
